	------test 根据ma5和10差值预判当天预计会出现金叉的票，结合实际走势买入（实际是将ma5上穿金叉提前一天）---- 
create or replace function getstma5im(days int) returns setof record as
$$
declare
rec record;
begin
  for rec in EXECUTE '
	select b."date",b.code,b.macd, --(b.ma10-b.ma5)/b.ma5 , 
	s."name",s.industry from basic_data b  left join stocks s  on b.code=s.code 
	  where to_date(b.date,''YYYY-MM-DD'') = getwd(current_date,'||days||')
	  and (b.ma10-b.ma5)/b.ma5 < 0.006 and ma5 < ma10
	  and volume < vol5*1.8 
	  and strpos(s."name",''ST'')=0
	  and macd::float8 >= -0.1 
	  and (select macd::float8 from basic_data where to_date(date,''YYYY-MM-DD'') = getwd(current_date,'||days+3||') and code=b.code ) <=0
	  and b."close"*b.volume>200000 --交易量大于2千万
	  and s."timeToMarket" <>0 and to_date(to_char(s."timeToMarket",''99999999''),''YYYYMMDD'') < current_date-180
	  and (select ma5 from basic_data where to_date(date,''YYYY-MM-DD'') = getwd(current_date,'||days+1||') and code=b.code ) <  (select ma10 from basic_data where to_date(date,''YYYY-MM-DD'') = getwd(current_date,'||days+1||') and code=b.code )
	  order by macd::float8
	 ;
' loop
    return next rec;
  end loop;
return;
end
$$
language 'plpgsql';